package com.linewow.xhyy.nihaonew.net.api;

import android.util.Log;

import com.linewow.xhyy.nihaonew.application.NiHaoApp;
import com.linewow.xhyy.nihaonew.base.BaseEntity;
import com.linewow.xhyy.nihaonew.base.BaseInfo;
import com.linewow.xhyy.nihaonew.base.SimpleBaseEntity;
import com.linewow.xhyy.nihaonew.entity.NiHaoGeneral;
import com.linewow.xhyy.nihaonew.entity.NiHaoVersionEntity;
import com.linewow.xhyy.nihaonew.entity.PushParams;
import com.linewow.xhyy.nihaonew.entity.UserMineInfo;
import com.linewow.xhyy.nihaonew.entity.baidu.BaiduInfo;
import com.linewow.xhyy.nihaonew.entity.baidu.TranslateInfo;
import com.linewow.xhyy.nihaonew.entity.image.ImagesInfo;
import com.linewow.xhyy.nihaonew.entity.image.SimpleImagesInfo;
import com.linewow.xhyy.nihaonew.entity.tag.CustomTagsInfo;
import com.linewow.xhyy.nihaonew.entity.tag.TagListInfo;
import com.linewow.xhyy.nihaonew.entity.topic.FindTagTopicInfo;
import com.linewow.xhyy.nihaonew.entity.topic.TopicDetailInfo;
import com.linewow.xhyy.nihaonew.entity.user.SimpleUserInfo;
import com.linewow.xhyy.nihaonew.entity.user.Uinfo;
import com.linewow.xhyy.nihaonew.entity.user.UserInfo;
import com.linewow.xhyy.nihaonew.model.HttpModel;
import com.linewow.xhyy.nihaonew.net.CallBack.JsonConvert;
import com.linewow.xhyy.nihaonew.util.CommonUtil;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.convert.StringConvert;
import com.lzy.okrx.RxAdapter;

import java.util.List;

import rx.Observable;

/**
 * Created by LXR on 2016/10/19.
 */
public class NiHaoOkgo {

    public static Observable<BaseInfo<List<ImagesInfo>>>simpleImagesInfo(int page){
        return  OkGo.get("https://huibenabc.com/api/api1.5/sousuo.php?ac=images")
                .params("token", NiHaoApp.token)
                .params("page",""+page)
                .getCall(new JsonConvert<BaseInfo<List<ImagesInfo>>>(){}, RxAdapter.<BaseInfo<List<ImagesInfo>>>create());
    }

    public static Observable<BaiduInfo<TranslateInfo>>baiduInfo(String q){
        int salt=CommonUtil.getSaltInt();
        Log.e("nihaoGo",""+salt);
        Log.e("nihaoGo",""+q);
        String sign=CommonUtil.getMD5("20160824000027361"+q+salt+"ZwdmKWO5PlPAwDPHRAF8");
        Log.e("nihaoGo","签名"+sign);
        return OkGo.post("http://api.fanyi.baidu.com/api/trans/vip/translate")
                .params("q",q)
                .params("from","auto")
                .params("to","auto")
                .params("appid","20160824000027361")
                .params("salt",salt)
                .params("sign",sign)
                .getCall(new JsonConvert<BaiduInfo<TranslateInfo>>(){},RxAdapter.<BaiduInfo<TranslateInfo>>create());
    }


    public static Observable<String>pushInfo(PushParams pushParams){

        return  OkGo.post("https://huibenabc.com/api/api1.6/jpush.php?ac=push&token="+NiHaoApp.token)
                .params("alias",pushParams.alias)
                .params("contents",pushParams.contents)
                .params("title",pushParams.title)
                .params("rid",pushParams.alias)
                .getCall(StringConvert.create(),RxAdapter.<String>create());
    }

    public static Observable<NiHaoGeneral<String>>zanInfo(FindTagTopicInfo<Uinfo, SimpleImagesInfo, CustomTagsInfo>info){
        return OkGo.post(HttpModel.USERLIKE+"&token="+NiHaoApp.token+"&rid="+info.rid)
                .params("tid",info.tid)
                .params("tuid",info.uid)
                .getCall(new JsonConvert<NiHaoGeneral<String>>(){},RxAdapter.<NiHaoGeneral<String>>create());
    }
    public static Observable<NiHaoGeneral<String>>zanInfo(TopicDetailInfo<ImagesInfo, Uinfo, CustomTagsInfo> info){
        return OkGo.post(HttpModel.USERLIKE+"&token="+NiHaoApp.token+"&rid="+info.rid)
                .params("tid",info.tid)
                .params("tuid",info.uid)
                .getCall(new JsonConvert<NiHaoGeneral<String>>(){},RxAdapter.<NiHaoGeneral<String>>create());
    }


    public static Observable<NiHaoGeneral<String>>zanInverseInfo(FindTagTopicInfo<Uinfo, SimpleImagesInfo, CustomTagsInfo>info){
        return OkGo.post(HttpModel.USERULIKE+"&token="+NiHaoApp.token+"&rid="+info.rid)
                .params("tuid",info.uid)
                .getCall(new JsonConvert<NiHaoGeneral<String>>(){},RxAdapter.<NiHaoGeneral<String>>create());
    }
    public static Observable<NiHaoGeneral<String>>zanInverseInfo(TopicDetailInfo<ImagesInfo, Uinfo, CustomTagsInfo> info){
        return OkGo.post(HttpModel.USERULIKE+"&token="+NiHaoApp.token+"&rid="+info.rid)
                .params("tuid",info.uid)
                .getCall(new JsonConvert<NiHaoGeneral<String>>(){},RxAdapter.<NiHaoGeneral<String>>create());
    }

    public static Observable<NiHaoGeneral<String>>signInfo(String sign_txt){
        return OkGo.post(HttpModel.USERSIGN+NiHaoApp.token)
                .params("sig_txt",sign_txt)
                .getCall(new JsonConvert<NiHaoGeneral<String>>(){},RxAdapter.<NiHaoGeneral<String>>create());
    }

    public static Observable<NiHaoGeneral<String>>nickInfo(String nickname){
        return OkGo.post(HttpModel.USERNICK+NiHaoApp.token)
                .params("nickname",nickname)
                .getCall(new JsonConvert<NiHaoGeneral<String>>(){},RxAdapter.<NiHaoGeneral<String>>create());
    }



    public static Observable<NiHaoGeneral<String>>adviceInfo(String content,String contact){
        return OkGo.post(HttpModel.USERADVICE+NiHaoApp.token)
                .params("content",content)
                .params("contact",contact)
                .getCall(new JsonConvert<NiHaoGeneral<String>>(){},RxAdapter.<NiHaoGeneral<String>>create());
    }

    public static Observable<NiHaoGeneral<String>>changePwdInfo(String oldPwd,String newPwd){
        return  OkGo.post(HttpModel.USERCHANGE+NiHaoApp.token)
                .params("oldpassword",oldPwd)
                .params("newpassword",newPwd)
                .getCall(new JsonConvert<NiHaoGeneral<String>>(){},RxAdapter.<NiHaoGeneral<String>>create());
    }

    public static Observable<BaseInfo<TagListInfo>>tagListInfo(){
        return OkGo.get(HttpModel.TOPICTAGLIST+NiHaoApp.token)
                .getCall(new JsonConvert<BaseInfo<TagListInfo>>(){},RxAdapter.<BaseInfo<TagListInfo>>create());
    }


    public static Observable<SimpleBaseEntity<String>> registerInfo(String email, String nickname, String pwd1, String pwd2){
        return  OkGo.post(HttpModel.USERREGISTER)
                .params("email",email)
                .params("nickname",nickname)
                .params("password",pwd1)
                .params("password1",pwd2)
                .getCall(new JsonConvert<SimpleBaseEntity<String>>(){}, RxAdapter.<SimpleBaseEntity<String>>create());
    }

    public  static Observable<SimpleBaseEntity<String>>loginInfo(String email,String pwd){
        return OkGo.post(HttpModel.USERLOGIN)
                .params("email",email)
                .params("password",pwd)
                .getCall(new JsonConvert<SimpleBaseEntity<String>>(){},RxAdapter.<SimpleBaseEntity<String>>create());

    }

    public static  Observable<BaseEntity<UserMineInfo<UserInfo,List<ImagesInfo>>>>userPhoto(String uid,int page){
        return  OkGo.get(HttpModel.USERMINE1)
                .params("tid",uid)
                .params("page",""+page)
                .params("token",NiHaoApp.token)
                .getCall(new JsonConvert<BaseEntity<UserMineInfo<UserInfo,List<ImagesInfo>>>>(){},RxAdapter.<BaseEntity<UserMineInfo<UserInfo,List<ImagesInfo>>>>create());

    }

    public static Observable<BaseInfo<FindTagTopicInfo<Uinfo,SimpleImagesInfo,CustomTagsInfo>>>userTopic(String uid,int page){
        return OkGo.get(HttpModel.USERTOPIC1)
                .params("tid",uid)
                .params("token",NiHaoApp.token)
                .params("page",""+page)
                .getCall(new JsonConvert<BaseInfo<FindTagTopicInfo<Uinfo,SimpleImagesInfo,CustomTagsInfo>>>(){},RxAdapter.<BaseInfo<FindTagTopicInfo<Uinfo,SimpleImagesInfo,CustomTagsInfo>>>create());
    }

    public static  Observable<NiHaoGeneral<String>>shieldInfo(String ac,String uid){
        return OkGo.get(HttpModel.USERSHIELD)
                .params("ac",ac)
                .params("token",NiHaoApp.token)
                .params("touid",uid)
                .getCall(new JsonConvert<NiHaoGeneral<String>>(){},RxAdapter.<NiHaoGeneral<String>>create());
    }

    public static Observable<NiHaoGeneral<String>>resetInfo(String email){
        return OkGo.post(HttpModel.RESET)
                .params("email",email)
                .getCall(new JsonConvert<NiHaoGeneral<String>>(){},RxAdapter.<NiHaoGeneral<String>>create());
    }

    public static  Observable<BaseInfo<SimpleUserInfo>> followListInfo(String uid,int page){
        return OkGo.get(HttpModel.USERFOLLOWLIST)
                .params("token",NiHaoApp.token)
                .params("tid",uid)
                .params("page",""+page)
                .getCall(new JsonConvert<BaseInfo<SimpleUserInfo>>(){},RxAdapter.<BaseInfo<SimpleUserInfo>>create());
    }
    public static  Observable<BaseInfo<SimpleUserInfo>> fanListInfo(String uid,int page){
        return OkGo.get(HttpModel.USERFANLIST)
                .params("token",NiHaoApp.token)
                .params("page",page)
                .params("tid",uid)
                .getCall(new JsonConvert<BaseInfo<SimpleUserInfo>>(){},RxAdapter.<BaseInfo<SimpleUserInfo>>create());
    }

    public static Observable<BaseInfo<SimpleUserInfo>> shieldListInfo(int page){
        return OkGo.get(HttpModel.USERSHIELDLIST)
                .params("token",NiHaoApp.token)
                .params("page",""+page)
                .getCall(new JsonConvert<BaseInfo<SimpleUserInfo>>(){},RxAdapter.<BaseInfo<SimpleUserInfo>>create());
    }

    public static  Observable<NiHaoGeneral<String>>setProfileInfo(String field,String value){
        return OkGo.post(HttpModel.SETPROFILE+NiHaoApp.token)
                .params("field",field)
                .params("value",value)
                .getCall(new JsonConvert<NiHaoGeneral<String>>(){},RxAdapter.<NiHaoGeneral<String>>create());
    }

    public static Observable<BaseEntity<NiHaoVersionEntity>>getVersion(String version){
        return OkGo.get(HttpModel.NIHAOVERSION)
                .params("xitong","Android")
                .params("token",NiHaoApp.token)
                .params("name",version)
                .getCall(new JsonConvert<BaseEntity<NiHaoVersionEntity>>(){},RxAdapter.<BaseEntity<NiHaoVersionEntity>>create());

    }

    public static Observable<NiHaoGeneral<String>>delTopic(String tid){
        return OkGo.get(HttpModel.USERDELETE)
                .params("tid",tid)
                .params("token",NiHaoApp.token)
                .getCall(new JsonConvert<NiHaoGeneral<String>>(){},RxAdapter.<NiHaoGeneral<String>>create());
    }

    public static Observable<NiHaoGeneral<String>>reportInfo(String tid,String info){
        return OkGo.post(HttpModel.USERREPORT+NiHaoApp.token)
                .params("tid",tid)
                .params("info",info)
                .getCall(new JsonConvert<NiHaoGeneral<String>>(){},RxAdapter.<NiHaoGeneral<String>>create());

    }
}
